home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_352 / treewalk / rexx / backup.rexx < prev    next >
OS/2 REXX Batch file  |  1992-05-06  |  3KB  |  100 lines

  1. /*
  2.  * backup - do daily backup of it's argument.
  3.  *
  4.  * For each argument dev (with no ':'), find all files on dev: that
  5.  * are newer than dev:last-backup, and copy them (complete with directory
  6.  * structure) to backup:
  7.  *
  8.  * See build-exclusions for how the exclusions list is built.
  9.  *
  10.  *    Copyright (C) 1989, 1990  Mike Meyer
  11.  *
  12.  *    This program is free software; you can redistribute it and/or modify
  13.  *    it under the terms of the Free Software License as published by
  14.  *    the Free Software Foundation; either version 1, or any later version.
  15.  *
  16.  *    This program is distributed in the hope that it will be useful,
  17.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  *    GNU General Public License for more details.
  20.  */
  21.  
  22. dev = arg(1)
  23. signal on error
  24. options failat 1
  25.  
  26. logfile = 'logs:backup.log'
  27.  
  28. if ~exists(logfile) then 'copy nil: to' logfile
  29.  
  30. if index(dev, ':') = 0 then dev = dev':'
  31.  
  32. call log 'Backup of' dev 'starting,' disksize('backup') 'blocks free on backup:'
  33. if exists(dev'last-backup') then
  34.     filter = "file && date > "dev"last-backup.date"
  35. else do
  36.     call log "Doing full backup of" dev
  37.     filter = "file"
  38.     end
  39.  
  40. call build_exclusions
  41. 'treewalk dir' dev' filter "'filter' && backup && false"'
  42. 'date >' dev'last-backup'
  43. call log 'Backup of' dev 'done,' disksize('backup') 'blocks free on backup:'
  44. call setclip "daily.backup"
  45. exit
  46.  
  47. /*
  48.  * build_exclusions - returns a treewalk filter expression to test
  49.  * names in the file against the exclusion list.
  50.  */
  51. build_exclusions: procedure expose logfile
  52.  
  53.     'execio read s:backup-exclusions stem excludes.'
  54.     out = "true"
  55.     do i = 1 to excludes.0
  56.         if left(excludes.i, 1) = '#' then iterate i
  57.         if verify(excludes.i, ":/", 'Match') = 0 then
  58.             out = out "&& name !* '"excludes.i"'"
  59.         else out = out "&& filename !* '"excludes.i"'"
  60.         end
  61.     call setclip "daily.backup", out
  62.     return
  63.  
  64. /*
  65.  * Returns the # of free blocks on the backup disk.
  66.  */
  67. disksize: procedure expose logfile
  68.  
  69.     'info | execio locate' arg(1) 'for 1 var dataline'
  70.     return word(dataline, 4)
  71.  
  72.  
  73. /*
  74.  * Catch command errors, and diagnose them for the user.
  75.  */
  76. error:
  77.  
  78.     if syntax = 2 then do
  79.         call log "Interrupted; backup incomplete." disksize('backup') "blocks free."
  80.         exit
  81.         end
  82.  
  83.     call log 'line' sigl 'failed; backup incomplete.'
  84.     call log disksize('backup') "blocks free on daily:"
  85.     exit
  86.  
  87. /*
  88.  * Log - log the message we've been given.
  89.  */
  90. log: procedure expose logfile
  91.     parse arg message
  92.  
  93.     if ~open(file, logfile, 'Append') then do
  94.         say "Can't open" logfile', exiting!'
  95.         exit
  96.         end
  97.     call writeln file, date() time() || ':' message
  98.     call close file
  99.     return
  100.